package com.milo.coding.concurrent.tools.countdown;

import java.util.concurrent.CountDownLatch;

public class CountDownLaunchRunner {

    static int sub = 0;
    static Object object = new Object();

    public static void main(String[] args) throws InterruptedException {
        long now = System.currentTimeMillis();
        // CountDownLatch countDownLatch = new CountDownLatch(2);
        //
        // new Thread(new SeeDoctorTask(countDownLatch)).start();
        // new Thread(new QueueTask(countDownLatch)).start();
        //
        // //等待线程池中的2个任务执行完毕，否则一直等待, zk分布式锁
        // countDownLatch.await();
        // System.out.println("over，回家 cost:"+(System.currentTimeMillis()-now));

        CountDownLatch countDownLatch = new CountDownLatch(10);
        for(int i=0;i<10;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    countDownLatch.countDown();
                    synchronized (object){
                        for(int j=0;j<1000;j++){
                            sub++;
                        }
                    }

                }
            }).start();
        }
        // Thread.sleep(3000);
        countDownLatch.await();

        System.out.println(sub);

    }

}
